
<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品名称</label>
    <div class="am-u-sm-9">
        <input type="text" name="name" data-required="1" class="span6" value="{$record.name}">
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品数量</label>
    <div class="am-u-sm-9">
        <input type="number" name="number" data-required="1" class="span3" value="{$record.number}"
               {if condition="$record"}readonly"{/if}>
    </div>
</div>

{if condition="$record"}
<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品剩余数量<span class="required">*</span></label>
    <div class="am-u-sm-9">
        <input type="number" name="current_number" data-required="1" class="span3" value="{$record.current_number}"
               {if condition="$record"}readonly{/if}>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">修改奖品剩余数量</label>
    <div class="am-u-sm-9">
        <label class="checkbox">
            <input type="checkbox" value="1" name="edit_number">修改奖品剩余数量
        </label>
    </div>
</div>
{/if}

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品排序</label>
    <div class="am-u-sm-9">
        <input type="number" name="sort" data-required="1" class="span3" value="{$record.sort}">
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品状态</label>
    <div class="am-u-sm-9">
        <select name="status">
            <option value="0">关闭</option>
            <option value="1" {eq name="$record.status" value="1"}selected{/eq}>开启</option>
        </select>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品是否无限</label>
    <div class="am-u-sm-9">
        <select name="is_endless">
            <option value="0">否</option>
            <option value="1" {eq name="$record.is_endless" value="1"}selected{/eq}>是</option>
        </select>
        <span class="am-form-help">当值为"是"时,则奖池内该奖品不会减少</span>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">是否有中奖记录</label>
    <div class="am-u-sm-9">
        <select name="is_log">
            <option value="1">记录</option>
            <option value="0" {eq name="$record.is_log" value="0"}selected{/eq}>不记录</option>
        </select>
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">中奖提示语句</label>
    <div class="am-u-sm-9">
        <input type="text" name="tip_text" data-required="1" class="span6" value="{$record.tip_text}">
    </div>
</div>

<div class="am-form-group">
    <label class="am-u-sm-3 am-form-label">奖品分类</label>
    <div class="am-u-sm-9">
        <select name="reward_cate">
            <option value="0">虚拟</option>
            <option value="1" {eq name="$record.reward_cate" value="1"}selected{/eq}>实体</option>
        </select>
    </div>
</div>

<div class="am-form-group receive">
    <label class="am-u-sm-3 am-form-label">兑换地址</label>
    <div class="am-u-sm-9">
        <input type="text" name="receive_address" data-required="1" class="span6" value="{$record.receive_address}">
    </div>
</div>

<div class="am-form-group">
    <div class="am-u-sm-9 am-u-sm-push-3">
        <button type="button" class="am-btn am-btn-primary form-btn">保存修改</button>
        <button type="button" class="am-btn" onclick="history.go(-1);">取消</button>
    </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">错误信息</div>
        <div class="am-modal-bd error_msg">
            Hello world！
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn">确定</span>
        </div>
    </div>
</div>

<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1" id="my-modal-loading">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">正在载入...</div>
        <div class="am-modal-bd">
            <span class="am-icon-spinner am-icon-spin"></span>
        </div>
    </div>
</div>
<script type="text/javascript">

    $('.form-btn').click(function(){

        var form = $(this).parents('form');
        var url = form.attr('action');
        var formData = form.serializeArray();
        $.ajax({
            url:url,
            type:'post',
            data:formData,
            dataType:'json',
            success:function(result){
                if(result.code == 0){
                    $('.am-modal-hd').text(result.message);
                    $('#my-modal-loading').modal('open');
                    timed();
                }else{
                    $('.error_msg').text(result.message);
                    $('#my-alert').modal('open');
                }
            }
        });
        return false;
    });

    function timed()
    {
        var t=setTimeout("location.href='{:url($code.'/index',['active_id'=>$active_id])}'",1000);
    }

    $('input[name=edit_number]').click(function(){
        if($(this).attr('checked') == 'checked'){
            $('input[name=current_number]').removeAttr('readonly');
        }else{
            $('input[name=current_number]').attr('readonly','readonly');
        }
    });

    change_reward('{$record.reward_cate}');

    function change_reward(val){
        if(val == 1){
            $('.receive').show();
        }else{
            $('.receive').hide();
        }
    }

    $('select[name=reward_cate]').change(function(){
        change_reward($(this).val());
    });
</script>